package me.algo.array;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author guozheng
 * @date 2024/4/20
 */
public class A5 {
    /**
     * 560. 和为 K 的子数组
     *
     * @param nums
     * @param k
     * @return
     */
    public int subarraySum(int[] nums, int k) {
        if (Objects.isNull(nums) || nums.length == 0) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int sum = 0;
            for (int j = i; j < nums.length; j++) {
                sum = nums[j] + sum;
                if (sum == k) {
                    count++;
                }
            }
        }
        return count;

    }

}
